package com.pkk.penguin.frame.know.java.driven.jdbc;

import com.pkk.penguin.frame.know.java.driven.jdbc.handle.JdbcHandleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * jdbc事务的配置类
 *
 * @author peikunkun
 * @version V1.0
 * @date 2020-10-21 18:01
 **/
@Slf4j
@EnableTransactionManagement
@ComponentScan(basePackages = "com.pkk.penguin.frame.know.java.driven.jdbc")
public class JdbcMainTests {


  public static void main(String[] args) {
    //过程分析
    analyzer();

    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(JdbcMainTests.class);
    final JdbcHandleService bean = applicationContext.getBean(JdbcHandleService.class);
    final boolean insert = bean.insert(false);
    System.out.println("保存结果:" + insert);
  }

  private static void analyzer() {
    log.info("↓↓↓↓↓↓↓↓↓↓↓↓↓↓此分析是简单的包引用,不受SpringBoot的自动配置化影响↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
    log.info("1.简单执行,方法内异常不受事务影响,异常也会操作成功");
    log.info("2.方法增加@Transactional注解,方法内异常不受事务影响,异常也会操作成功,因为事务注解没有开启");
    log.info("2.配置类或者启动类增加@EnableTransactionManagement注解,开启注解方式事务配置;方法内异常影响事务,事务回滚,但是报出[No qualifying bean of type 'org.springframework.transaction.PlatformTransactionManager' available]");
    log.info("3.配置事务管理器PlatformTransactionManager,");
    log.info("↑↑↑↑↑↑↑↑↑↑↑↑↑↑此分析是简单的包引用,不受SpringBoot的自动配置化影响↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑");

  }

}
